Reduce context usage for get_pull_request_review_comments using pull_request_read#2062
Merged
tommaso-moro merged 2 commits intomainfrom Feb 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces token/context usage for pull_request_read’s get_review_comments path by returning a minimized, flattened representation of PR review threads/comments instead of the raw GraphQL-shaped payload.
Changes:
- Introduces minimal output types + converters for PR review threads/comments (flattened authors, flattened comment nodes, dropped GraphQL IDs).
- Updates
GetPullRequestReviewCommentsto return the new minimal response viaMarshalledTextResult. - Updates
pullrequests_test.goassertions to validate the typed minimal response shape.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/github/pullrequests.go |
Switches review-comments response to marshalled minimal response type. |
pkg/github/minimal_types.go |
Adds minimal structs and converters for review threads/comments + pagination. |
pkg/github/pullrequests_test.go |
Updates tests to unmarshal and assert on MinimalReviewThreadsResponse. |
omgitsads
previously approved these changes
Feb 23, 2026
omgitsads
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes:
Summary
This PR reduces the context window usage when fetching pull request review comments using the
pull_request_readtool (get_review_comments).It does so by using the minimal types pattern (which is already used elsewhere in the codebase for the same reason) to reduce the payload that is sent back to the model when the tool is used. Specifically, GraphQL node IDs are removed, nested author objects are flattened to plain strings, and the
Comments.Nodesnesting is flattened to a directcommentsarray, eliminating unnecessary JSON noise per review thread.Tests & Metrics
When tested with this PR:
Before: 6815 tokens
After: 5823 tokens
Context reduction: 14.56%
Fields preserved
Thread:
is_resolved,is_outdated,is_collapsed,comments,total_countComment:
body,path,line,author(flattened fromAuthor.Login),created_at,updated_at,html_url(fromURL)Pagination:
has_next_page,has_previous_page,start_cursor,end_cursor,total_countFields dropped
Thread
ID(GraphQL node ID, not used for pagination or any subsequent tool call), CommentID(GraphQL node ID, not useful for reasoning —html_urlis the meaningful identifier)Why
The raw GraphQL response returned by the GitHub API includes GraphQL node IDs on both threads and comments, deeply nested author objects (
Author.Login), and a nestedComments.Nodesarray structure that add up across threads and waste context window on every call. These fields are not used by models for reasoning or follow-up tool calls — pagination relies on cursors, and thehtml_urlserves as the useful comment identifier.What changed
MinimalPageInfo,MinimalReviewComment,MinimalReviewThread, andMinimalReviewThreadsResponsetypes tominimal_types.goconvertToMinimalReviewThreadsResponse,convertToMinimalReviewThread, andconvertToMinimalReviewCommentconverter functionsGetPullRequestReviewCommentsto return viaMarshalledTextResultinstead of manualjson.Marshalof raw GraphQL structsMinimalReviewThreadsResponsefields instead ofmap[string]anyMCP impact
Security / limits
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testDocs